package com.service.impl;

import com.entity.Material;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mapper.MaterialMapper;
import com.service.MaterialService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.utils.PageObject;
import com.vo.MaterialVO;
import com.vo.OrdersVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  物料服务实现类
 * </p>
 *
 * @author aiou
 * @since 2025-06-09
 */
@Service
public class MaterialServiceImpl implements MaterialService {

    @Autowired
    private MaterialMapper materialMapper;

    //查询所有物料
    @Override
    public List<Material> list() {
        return materialMapper.selectAll();
    }

    //物料管理：删除物料
    @Override
    public boolean removeById(Integer id) {
        return materialMapper.delete(id);
    }

//    物料管理：分页查询
    @Override
    public PageObject<MaterialVO> list(PageObject pageObject) {
        //开始分页
        PageHelper.startPage(pageObject.getCurrent(),pageObject.getSize());
        //查询数据
        List<MaterialVO> list = materialMapper.list();
        //PageHelper包装数据
        PageInfo<MaterialVO> pageInfo = new PageInfo<>(list);
        //将数据封装进PageResult
        PageObject<MaterialVO> MaterialPageResult
                = new PageObject<>(pageInfo.getPageNum(), pageInfo.getPageSize(), pageInfo.getTotal(), pageInfo.getList());
        return MaterialPageResult;
    }

    //根据物料编码查询
    @Override
    public Material getOne(String materialCode) {
        return materialMapper.getOne(materialCode);
    }

    //物料管理：保存物料
    @Override
    public boolean save(Material material) {
        return materialMapper.save(material);
    }

    //物料管理：修改物料
    @Override
    public boolean updateById(Material material) {
        return materialMapper.update(material);
    }
}
